package com.woniuxy.shop.servelet.manager;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.alipay.api.domain.Shop;
import com.woniuxy.shop.entity.PageBean;
import com.woniuxy.shop.entity.User;
import com.woniuxy.shop.service.ServiceProxyFactory;
import com.woniuxy.shop.service.UserService;
import com.woniuxy.shop.utils.ShopUtils;

/**
 * Servlet implementation class UserServlet
 */
@WebServlet("/manager/user")
public class UserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
     UserService us = ServiceProxyFactory.getProxy(UserService.class);
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String opr = request.getParameter("opr");
		if("show".equals(opr)) {
			doShow(request,response);
		}
	}

	private void doShow(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		int page = 1; 
		User u = new User();
		String name = request.getParameter("name");
		String email = request.getParameter("email");
		String status = request.getParameter("status");
		String sminscore = request.getParameter("minscore");
		String smaxscore = request.getParameter("maxscore");
		String spage = request.getParameter("nowpage");
		if(!ShopUtils.isEmpty(spage)) {
			page = Integer.parseInt(spage);
		}
		if(!ShopUtils.isEmpty(name)) {
			u.setAccount(name.trim());
		}
		if(!ShopUtils.isEmpty(status)) {
			u.setStatus(status.trim());
		}
		if(!ShopUtils.isEmpty(sminscore)) {
			u.setMinscore(Integer.parseInt(sminscore));
		}
		if(!ShopUtils.isEmpty(smaxscore)) {
			u.setMaxscore(Integer.parseInt(smaxscore));
		}
		if(!ShopUtils.isEmpty(email)) {
			u.setEmail(email.trim());
		}
		PageBean<User> pb = us.getPageBean(page, u);
		request.setAttribute("pb", pb);
		request.setAttribute("user", u);
		request.getRequestDispatcher("user/user_list.jsp").forward(request, response);
		
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
